#include<bits/stdc++.h>
using namespace std;
namespace IO{
    const int BUF=1<<21;
    char buff[BUF],*p1=buff,*p2=buff;
    #define getchar() (p1==p2&&(p2=((p1=buff)+fread(buff,1,BUF,stdin)),p1==p2)?EOF:*p1++)
    template<typename T>inline void read(T &x){
        char ch=getchar();x=0;int f=1;
        while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
        while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
        x*=f;
    }
}
using namespace IO;
const int N=5e5+5;
#define ll long long
const ll inf=-1e17;
int n,k,d,a[N],cnt[N];
ll f[N],tag[N];
struct heap{
	priority_queue<ll> h,d;
	inline void push(ll x){h.push(x);}
	inline void del(ll x){d.push(x);}
	inline ll Top(){
		while(!d.empty()&&h.top()==d.top()) h.pop(),d.pop();
		return h.empty()?inf:h.top();
	}
}h[N],T;
vector<int> D[N];
int main(){
	freopen("holiday.in","r",stdin);
	freopen("holiday.out","w",stdout);
	read(n),read(k),read(d);
	for(int i=1;i<=n;++i) read(a[i]);
	for(int i=1,x;i<n;++i){
		read(x);
		D[x+i+1].push_back(i);
	}
	h[1%k].push(f[1]=a[1]);
	T.push(f[1]);
	cnt[1%k]=1;
	for(int i=2;i<=n;++i){
		for(int j:D[i]){
			T.del(h[j%k].Top()-tag[j%k]);
			h[j%k].del(f[j]);
			T.push(h[j%k].Top()-tag[j%k]);
			--cnt[j%k];
		}
		int m=i%k;
		if(cnt[m]) T.del(h[m].Top()-tag[m]);
		tag[m]+=d;
		f[i]=a[i]+max(T.Top(),h[m].Top()-tag[m])+tag[m];
		++cnt[m];
		h[m].push(f[i]);
		T.push(h[m].Top()-tag[m]);
	}
	printf("%lld\n",f[n]-tag[n%k]);
	return 0;
}

